﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Runda.CMS.Common.Utility;
using Runda.CMS.Common.Entity;
using Runda.CMS.Dal;

namespace Runda.CMS.Bll
{
    public class MasterDataBll:BllBase
    {
        private string CacheName = "GetAllDictionary";

        public MasterDataBll()
        {
            _cacheName = "DictionaryAllCache";
        }

        #region Dictionary

        public List<SysDictionaryEntity> GetAllDictionaryFromCache()
        {

            if (base.ExistsCacheData(CacheName))
            {
                return GetCacheData(CacheName) as List<SysDictionaryEntity>;
            }
            else
            {
                SysDictionaryDal dal = new SysDictionaryDal();
                List<SysDictionaryEntity> list = dal.GetAll<SysDictionaryEntity>(" and Deleted = 0");

                AddCache(CacheName, list);

                return list;
            }

        }

        public List<SysDictionaryEntity> GetDictionaryListFromCache(Enumerator.DictionaryType type)
        {
            if (base.ExistsCacheData(CacheName))
            {
                List<SysDictionaryEntity> list = null;
                list = GetCacheData(CacheName) as List<SysDictionaryEntity>;

                return list.FindAll(delegate(SysDictionaryEntity e) { return e.Type == (int)type; });
            }
            else
            {
                SysDictionaryDal dal = new SysDictionaryDal();
                List<SysDictionaryEntity> list = dal.GetAll<SysDictionaryEntity>(" and Deleted = 0");

                AddCache(CacheName, list);

                return list.FindAll(delegate(SysDictionaryEntity e) { return e.Type == (int)type; });
            }
        }

        #endregion

    }
}
